package com.wjggy.core.service.user.Impl;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import com.wjggy.core.common.dbtools.DaoUtils;
import com.wjggy.core.common.util.cookie.CookieUtils;
import com.wjggy.core.entities.User;
import com.wjggy.core.service.user.LoginService;


 /**
 *  <p>Description:  </p>
 *  <p>Copyright:Copyright (c) 2012  </p>
 *  <p>Company:wjggy  </p>
 *  @author xiaofan.yu  
 *  @date   2012-1-9 上午10:45:11    
 *  @project  wjggy
 *  @version  1.0.0
 *  @see   
 *  @since 1.6 
 */
@Service("loginService")
public class LoginServiceImpl implements LoginService {
	private static final Logger log = Logger.getLogger(LoginServiceImpl.class);
	@Resource(name="daoUtils")
	private DaoUtils daoUtils;
	@Override
	public int loginAdmin(HttpServletResponse response, User admin,
			String addAuthCode) {
		User adminInfo=(User) daoUtils.findObject("user.queryEmail", admin);
		if(adminInfo==null){//无改用户
			return -1;
		}else if(!adminInfo.getIsadmin()){//不是管理员
			return 3;
		}else if(adminInfo.getUserpass().equals(admin.getUserpass())){//
			CookieUtils.loginWriter(response, adminInfo, "-1");
			return 1;
		}
		return 0;//密码错误
	}
}

